import Taro, { useDidShow } from '@tarojs/taro';
import Storage from '@/utils/storage';

export function useLoginInterCeptor(func) {
  useDidShow(async () => {
    const token = await Storage.getItem('token');
    if (token) {
      func();
    } else {
      Taro.showModal({
        content: '您还没有登录,不能编辑简历',
        cancelText: '再想想',
        cancelColor: '#8799a3',
        confirmColor: '#48cfad',
        confirmText: '去登录',
        success: function (res) {
          if (res.confirm) {
            Taro.navigateTo({
              url: '/pages/login/index',
            });
          } else if (res.cancel) {
            Taro.switchTab({
              url: '/pages/index/index',
            });
          }
        },
      });
    }
  });
}
